package com.bdqn.controller;

import com.alibaba.fastjson.JSON;
import com.bdqn.bean.Result;
import com.bdqn.bean.course.Course;
import com.bdqn.bean.course.CourseType;
import com.bdqn.dao.imp.CourseTypeDaoImp;
import com.bdqn.service.ICourseTypeService;
import com.bdqn.service.imp.CourseTypeServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 忍
 * @title: CourseTypeController
 * @projectName Teaching
 * @description: TODO
 * @date 2019/4/2614:27
 */
@RestController
public class CourseTypeController {
    @Autowired
    HttpServletRequest request;
    @Autowired
    private ICourseTypeService courseTypeSerivce;


    @GetMapping("/search/{name}")
    public String findCourseTypeByName(@PathVariable String name){
        return JSON.toJSONString(courseTypeSerivce.findCourseTypeByName(name));
    }

    /**
     * @param id
     * @return java.util.List<com.bdqn.bean.course.CourseType>
     * @throws
     * @description: 根据方向id 查找分类
     * @author Mr.Zhou
     * @date 2019/4/26 23:30
     */
    @GetMapping("/type/{id}")
    public String findCourseTypeByDirectionId(@PathVariable int id) {
        return JSON.toJSONString(courseTypeSerivce.findCourseTypeByDirectionId(id));
    }
    //实现页面跳转
//    @GetMapping("/courses/{id}")
//    public ModelAndView findCourseByCourseType(@PathVariable int id){
//        ModelAndView mv = new ModelAndView();
//        mv.setViewName("course");
//        return mv;
//    }
    //根据课程id和课程等级获取课程
    @GetMapping(" ")
    public ModelAndView findCourseByCourseTypeLevel(@PathVariable int id,@PathVariable Integer level){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("course");
        return mv;
    }
    //根据课程id获取课程
//    @GetMapping(value = "/course")
//    public String selectCourseByCourseType(@RequestParam String id, @RequestParam(required=false,defaultValue = "1") String level){
////        return JSON.toJSONString(courseTypeSerivce.findCourseByCourseType(id));
//        return  JSON.toJSONString(new Result("success","id+"+id+",level"+level));

    //}
}
